//
//  LittleBallGameManagement.h
//  LittleBall
//
//  Created by mac on 11-12-23.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
#import <UIKit/UIKit.h>
#import "LBData.h"
#import "LBViewChangeAnimationDelegate.h"

#define GAME_DATA_FILE_NAME @"LBDataSave.dat"

#define NUMOFDATATOSTORE      5

#define INITGAMEDIFFICULTY    0
#define INITSCORE             0
#define INITMONEY             0
#define INITMUSICVOLUME       5     // 使用时除10
#define INITSOUNDVOLUME       5     // 使用时除10


#define BALL_NUM_CLEAR              5 // 小球消除判定个数

#define PROPERTY_TIMER_INTERVAL     0.1 
#define SYS_TIMER_INTERVAL          1 
#define BAL_GEN_INTERVAL_EASY       (8/SYS_TIMER_INTERVAL) 
#define BAL_GEN_INTERVAL_MEDIUM     (6/SYS_TIMER_INTERVAL)
#define BAL_GEN_INTERVAL_HARD       (4/SYS_TIMER_INTERVAL)

#define RANDOM_BALL_GEN_NUM_INIT_TRADITIONAL_EASY      3
#define RANDOM_BALL_GEN_NUM_INIT_TRADITIONAL_MEDIUM    4
#define RANDOM_BALL_GEN_NUM_INIT_TRADITIONAL_HARD      5

#define RANDOM_BALL_GEN_NUM_INIT_SURVIVAL_EASY     3
#define RANDOM_BALL_GEN_NUM_INIT_SURVIVAL_MEDIUM   4
#define RANDOM_BALL_GEN_NUM_INIT_SURVIVAL_HARD     5

#define INIT_NUMBER_TRADITIONAL_EASY       5
#define INIT_NUMBER_TRADITIONAL_MEDIUM     8
#define INIT_NUMBER_TRADITIONAL_HARD       10

#define INCREASE_BALL_GEN_NUM_INTERVER (240/SYS_TIMER_INTERVAL)
#define MAX_BALL_GEN_NUM            10

#define DEAD_PROMPT                 "天下没有不散的筵席"
#define DEAD_CANCEL_TEXT            "<重头来过>"

#define BALL_COLOR_NUM              4
#define BALL_NUM_MAX                (MAX_ROW*MAX_COLUMN)
#define BALL_WIDTH                  70
#define BALL_HEIGHT                 70
  
#define CENTER_POINT_X_CORRECT      0
#define CENTER_POINT_Y_CORRECT      0

#define COORDINATE_START_X          34
#define COORDINATE_START_Y          40

#define MAX_ROW                     10
#define MAX_COLUMN                  10


enum LBErrorCodeType 
{
    LB_ERROR = -1,
    LB_SUCCESS = 0,
    
    LB_BALL_EXIST = 1,
    LB_BALL_NOT_EXIST = 2,
    
    LB_BALL_ALREADY_SELECTED = 3,
    LB_BALL_NOT_SELECTED = 4
};

typedef enum
{
    EFFECT_SOUND_CLEARBALL = 0,
    EFFECT_SOUND_WIN,
    EFFECT_SOUND_LOSE,
    EFFECT_SOUND_BUTTON,
    EFFECT_SOUND_DEFAULT
}EFFECT_SOUND_TYPE;

typedef enum
{
    TRADITONAL_MODE,
    SURVIVAL_MODE
}GAME_MODE;

typedef enum
{
    EASY,
    MEDIUM,
    HARD
}DIFFICULTY;

//typedef enum
//{
//    LB_HONOR_STAGE0 = 0,
//    LB_HONOR_STAGE1,
//    LB_HONOR_STAGE2,
//    LB_HONOR_STAGE3,
//    LB_HONOR_STAGE4
//}LB_HONOR_STAGE;

@interface LittleBallGameManagement : NSObject
{    
    AVAudioPlayer         *m_soundEffectsPlayerForClearBall;
    AVAudioPlayer         *m_soundEffectsPlayerForWin;
    AVAudioPlayer         *m_soundEffectsPlayerForLose;
    AVAudioPlayer         *m_soundEffectsPlayerForButton;
    AVAudioPlayer         *m_soundEffectsPlayerForDefault;
    AVAudioPlayer         *m_backGroundSoundPlayer;
    
    NSError               *m_err;
    LBData                *gameData;
    
    LBViewChangeAnimationDelegate *m_viewChangeAnimationDelegate;
    
    NSArray               *m_honorStrArray; // 存放honor对应的名头字串，在initEx中被初始化，不能更改
}

- (void)loadBackgroundMusicwithName:(NSString *)audioName Type:(NSString*)audioType;
- (void)loadSoundEffectwithName:(NSString *)audioName fileType:(NSString *)audioType goal:(EFFECT_SOUND_TYPE)type;
- (void)playSoundEffectWithType:(EFFECT_SOUND_TYPE)type;
- (void)playBackgroundMusic;
- (void)continuePlayMusic;
- (void)stopBackgroundMusic;

// 获取设置
- (float)getMusicVolume;
- (float)getSoundVolume;
- (int)getGameDifficluty;

// 保存设置
- (void)setGameDifficulty:(DIFFICULTY)input;
- (void)setVolumeOfMusic:(float)musicVolumeInput Sound:(float)soundVolumeInput;
- (void)setPlayInfoWithScore:(int)sc Money:(int)mn Honor:(int)hn;

- (BOOL)readDataFromFile;
- (BOOL)WriteDataIntoFile;
- (BOOL)ifFileExists;

-(id)initEx;

@property (retain, nonatomic) LBData *gameData;
@property (retain, nonatomic) LBViewChangeAnimationDelegate *m_viewChangeAnimationDelegate;
@property (retain, nonatomic) NSArray *m_honorStrArray;

@end































